package com.yike.user.service.impl;

import com.yike.user.entity.PlatformUserRole;
import com.yike.user.mapper.PlatformUserRoleMapper;
import com.yike.user.service.PlatformUserRoleService;
import com.yike.user.param.PlatformUserRolePageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 平台用户角色 服务实现类
 *
 * @author Sakura
 * @since 2024-10-29
 */
@Slf4j
@Service
public class PlatformUserRoleServiceImpl extends BaseServiceImpl<PlatformUserRoleMapper, PlatformUserRole> implements PlatformUserRoleService {

    @Autowired
    private PlatformUserRoleMapper platformUserRoleMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean savePlatformUserRole(PlatformUserRole platformUserRole) throws Exception {
        return super.save(platformUserRole);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updatePlatformUserRole(PlatformUserRole platformUserRole) throws Exception {
        return super.updateById(platformUserRole);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deletePlatformUserRole(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<PlatformUserRole> getPlatformUserRolePageList(PlatformUserRolePageParam platformUserRolePageParam) throws Exception {
        Page<PlatformUserRole> page = new PageInfo<>(platformUserRolePageParam, OrderItem.desc(getLambdaColumn(PlatformUserRole::getCreateTime)));
        LambdaQueryWrapper<PlatformUserRole> wrapper = new LambdaQueryWrapper<>();
        IPage<PlatformUserRole> iPage = platformUserRoleMapper.selectPage(page, wrapper);
        return new Paging<PlatformUserRole>(iPage);
    }

}
